<?php
/*
Copyright (C) 2009 de Flotte Maxence

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
?>
<?php

class Zlog_readCategory extends Bout {
	

	protected function construct() {
	
		//Constructeur

			//Ouverture et definition des valeur par défaut du fichier de configuration
	
	}
	
	public function build() {
		//On récupère le nombre d'article à afficher
		$this->getIO()->need('nbArticle');
		//On récupère l'ordre dans lesquel on doit les afficher
		$this->getIO()->need('order');
		//On definni le nombre d'article par page
		$this->getIO()->setNbChildsPerPage($this->getIO()->get('nbArticle')->out());
		//On inverse l'ordre des article si 'order' == true 
		if($this->getIO()->get('order')->out() == '1')
			$this->getIO()->reverseChildsOrder();
		$return = '';
		//On parcour les n enfants de type 'article' (depuis le n * numéro de page+1)
		foreach($this->getIO()->getChilds('article') as $article) {
			//On veux le titre, l'auteur, la date de création, et le corps de l'article
			$article->need('name');
			$article->need('user');
			$article->need('dateC');
			$article->need('body');
			//On génère la structure de l'article
			$return .= '
				<div class="article">
					<h2 class="titre"><a href="'.getChildUrl($article->get('id')->out()).'">'.$article->get('name')->out().'</a></h2>
					<div class="author">Par '.$article->get('user')->getNickname().'</div>
					<div class="date">le '.$article->get('dateC')->format('d/m/Y').'</div>
					<div class="body">
						'.$article->get('body')->out().'
					</div>
				</div>';
		}
		//On affiche les articles
		return $return.$this->getIO()->getListPage();
	}
}

?>